<?php 
	require 'Admin/Model/UserModel.php';
	require 'Controller.php';
	class UserController extends Controller{
		function __construct(){
			parent::__construct();
		}
		function listusers(){
			$model=new UserModel();
			$data=$model->getUserList();
			//return $data;

			$this->assign('users',$data);
			$this->display();//送到view层显示数据
			
		}
		function deluser(){
			$uid=$_GET['uid'];
			$model= new UserModel();
			$result=$model -> delUser($uid);
			if ($result) {
				echo "删除成功! 3秒后条转回用户列表页";
				header("refresh:3;url='admin.php?c=user&m=listusers'");
			}
			else{
				echo "删除失败！";
				echo "<a href='admin.php?c=user&m=listusers'>返回列表</a>";
				
			}
		}
		function reguser(){
			$this->display();
		}
		function adduser(){
			$data=$_POST;
			$file=$_FILES;
			$model=new UserModel();
			$result=$model->adduser($data,$file);
			if ($result) {
				echo "注册成功，3秒后返回用户列表";
				header("refresh:3;url='admin.php?c=user&m=listusers'");
			}else{
				echo "注册失败，3秒后返回注册页面重新注册";
				header("refresh:3;url='admin.php?c=user&m=reguser'");
			}

		}
		function edituser(){ //拿到数据给model层  得到数据给View层显示
			$uid=$_GET['uid'];
			$model= new UserModel();
			$data=$model -> edituser($uid);

			$this->assign('user',$data);//送到view层显示数据
			$this->display();//送到view层显示数据
		}

		function updateuser(){
			$data=$_POST;
			$file=$_FILES;
			$model=new UserModel();
			$result=$model->updateuser($data,$file);
			if ($result) {
				echo "修改成功! 3秒后条转回用户列表页";
				header("refresh:3;url='admin.php?c=user&m=listusers'");
			}
			else{
				echo "修改失败！";
				echo "<a href='admin.php?c=user&m=listusers'>返回列表</a>";
				
			}

		}
		
	}
 ?>